<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://ckeditor.com" prefix="ckeditor" %>
<%@page import="com.ckeditor.CKEditorConfig"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<%@ include file="/static/htm/head" %>
		<title>游戏论坛帖子专区</title>
	</head>
	<body style="font-size:15px;">
		<div style="text-align: center;">
			<a href="index.jsp">
				<img alt="论坛Logo" height="56" src="static/pic/logo.jpg" width="192">
			</a>
		</div>
		<table width="100%">
			<tr>
				<td>
					<a href="postlist?id=${post.type}">
						返回帖子列表
					</a>
				</td>
				<td style="text-align: right;">
					<%@ include file="/static/htm/user.jsp"%>
				</td>
			</tr>
		</table>
		<!-- 帖子和回复的帖子部分 -->
		<div style="width:70%;position:relative;left:15%;min-height: 200px; border: solid 1px #E6E6E6; ">
			<h2 style="color:#003500">${post.title }</h2>
			<!-- 设置访问量和回复量 -->
			<span style="font-size: 12px; line-height: 30px;">本主题共有${ccount}回复，欢迎积极参加回帖</span><br>
			<a class="btn btn-success" href="readpost?postid=${param.postid }#foot" style="width:40px;margin-bottom: 10px;">回复</a>
			<!-- 帖子内容开始 -->
			<c:if test="${pageid eq 1}">
			<div>
				<div style="width:100%;height: 25px; background-color: #EAF4FF;">
					<span style="width:175px;text-align:center;">${post.postTime }</span>
					<span style="position:absolute;left:175px;">楼主</span>
				</div>
				<table width="100%" style="border-bottom: inset 1px #E6E6E6;">
					<tr>
						<td style="width:175px; background-color: #EAF4FF;">
							<div style="width:100%;min-height: 200px;text-align: center; padding-top: 50px;">
								<!-- 设置头像 -->
								<img alt="头像" width="100px" height="100px" src="static/pic/users/${cus[post.userId]['headPicturePath'] }"><br>
								<span style="line-height: 40px;"><a href="index.jsp?userid=${post.userId }">${post.userName }</a></span>
							</div>
						</td>
						<td valign="top">
							${post.content }
						</td>
					</tr>
				</table>
			</div>
			</c:if>
			<!-- 帖子内容结束 -->
			<c:if test="${comments ne null }">
				<c:if test="${pageid eq null}"><c:set var="pageid" value="1"/></c:if>
				<c:forEach var="comment" items="${comments }" varStatus="num">
				<div class="item">
					<div style="width:100%;height: 25px; background-color: #EAF4FF;">
						<span style="width:175px;text-align:center;">${comment.commentTime }</span>
						<span style="position:absolute;left:175px;">${(pageid-1)*5 + num.index + 1 }楼</span>
					</div>
					<table width="100%" style="border-bottom: inset 1px #E6E6E6;">
						<tr>
							<td style="width:175px; background-color: #EAF4FF;">
								<div style="width:100%;min-height: 200px;text-align: center; padding-top: 50px;">
									<img alt="头像" width="100px" height="100px" src="static/pic/users/${cus[comment.userId]['headPicturePath']}"><br>
									<span style="line-height: 40px;"><a href="index.jsp?userid=${comment.userId }">${cus[comment.userId]["userName"]}</a></span>
								</div>
							</td>
							<td valign="top">
								${comment.content }
							</td>
						</tr>
					</table>
				</div>
				</c:forEach>
			</c:if>
			<c:if test="${ comment ne null}">
			</c:if>
			<div style="width:100%;min-height: 50px;">
					<!-- 开始分页 -->
			 <div class="btn-toolbar" style="float:right;">
			        <div class="btn-group">
			          <a class="btn" href="readpost?postid=${param.postid}&pageid=1">回首页</a>
			          	<c:if test="${pageid -10 > 0 }">
			          		 <a class="btn" href="readpost?postid=${param.postid}&pageid=${pageid -10}">前10页</a>
			          	</c:if>
			          		 <a class="btn active btn-success" href="readpost?postid=${param.postid}&pageid=${pageid}">${pageid }</a>			          	
			          	<%
			          		int pageId = (Integer)request.getAttribute("pageid");
			          		int pageCount = (Integer)request.getAttribute("pagecount");
			          		for(int i = 1; i < 10; i++) {
			          			if(pageId + i > pageCount){
			          				break;
			          			}
			          			else {
			          	%>
			          	
			          		 <a class="btn" href="readpost?postid=${param.postid}&pageid=<%=pageId + i %>"><%=pageId + i %></a>
			          	<%
			          			}
			          		}
			          	%>
			          	<c:if test="${pageid + 10  < pagecount}">
			          		 <a class="btn" href="readpost?postid=${param.postid}&pageid=${pageid + 10}">后10页</a>
			          	</c:if>			    
			          <a class="btn" href="readpost?postid=${param.postid}&pageid=${pagecount}">跳末页</a>			          	     
			         <a class="btn">共${pagecount }页</a>
			        </div>
			      </div>
			</div>
			</div>
		<!-- 开始回帖部分 -->
		<div style="width:70%;position:relative;left:15%;min-height: 300px; border: solid 1px #E6E6E6; margin-top:20px;">
			<a name="foot"></a>
			<div style="background-color: #EAF4FF;padding-top: 10px;padding-bottom: 10px; padding-left:10px;">
				我来回复
			</div>
			<form action="permit/comment" method="post">
				<input type="hidden" name="postid" value="${param.postid}"/>
				<div id="response" style="width:100%;padding-left:10px;">
					<% 
						Map<String, String> attr = new HashMap<String, String>();
						attr.put("rows", "8");
						attr.put("cols", "50");
						CKEditorConfig settings = new CKEditorConfig();
						settings.addConfigValue("width", "70%");
						settings.addConfigValue("height","200px");
						settings.addConfigValue("toolbar", "Comment");
					%>
					<ckeditor:editor textareaAttributes="<%=attr %>"
						basePath="/gameforum/ckeditor/" config="<%=settings %>"
						editor="content" value="${value }"/>
					<div class="alert alert-error" style="font-size: 12px;margin-top: 5px;margin-bottom: 5px;width:200px;max-height:20px;" id="info">
					</div>
					<input type="submit" value="发表回复" class="btn btn-success" style="margin-top:5px;">
				</div>
				</form>				
		</div>
		<div style="width:70%;position:relative;left:15%; border: solid 1px #E6E6E6; margin-top:20px;">
				游戏论坛文明公约<br>
				一、守法正直。不触及敏感政治话题，不发表极端言论。在涉及公众利益、公共秩序等问题时，应遵守国家法律法规、社会伦理道德；<br>
				二、尊重他人，包容友爱。反对人身攻击、地域攻击等伤害论坛用户感情的言语和行为；<br>
				三、文明发言，礼貌待人。反对色情暴力等不健康内容，反对侮辱、谩骂等不文明行为；<br>	
		</div>
		<%@ include file="/static/htm/foot.jsp" %>
	</body>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#info").hide();
			$("input[type=submit]").click(function(){
				var editor = CKEDITOR.instances.content;
				var doc = editor.document;
				if(doc.getBody().getText().length < 5) {
					$("#info").html("请认真回复，切莫灌水 ");
					$("#info").show();
					return false;
				} else {
					return true;
				}
			});
		});
	</script>
</html>